﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_DAL;
using Zor_Modes;

namespace Zor_Bll
{
    public class CredentialInfo_Bll
    {
        /// <summary>
        /// 添加房屋证件信息
        /// </summary>
        /// <param name="ci"></param>
        /// <returns></returns>
        public static BaseAnswer InserCredentialInfo(CredentialInfo ci)
        {
            BaseAnswer bar = CredentialInfo_DAL.InserCredentialInfo(ci);
            if (bar.AnswerType == BaseAnswer.Answers.Succee)
                bar.AnswerMeg = "添加成功！";
            else if (bar.AnswerType == BaseAnswer.Answers.Failure)
                bar.AnswerMeg = "添加失败，请重试！";
            return bar;
        }

        /// <summary>
        /// 添加房屋证件信息
        /// </summary>
        /// <param name="ci"></param>
        /// <returns></returns>
        public static BaseAnswer addCredentialInfo(CredentialInfo ci)
        {
            BaseAnswer bar = new BaseAnswer();
            List<CredentialInfo> silst = CredentialInfo_DAL.GetCredentialInfoList(ci);
            if (silst.Count > 0)
            {
                bar = CredentialInfo_DAL.UpdateCredentialInfo(ci);
            }
            else 
            {
                bar = CredentialInfo_DAL.InserCredentialInfo(ci);
            }
            if (bar.AnswerType == BaseAnswer.Answers.Succee)
                bar.AnswerMeg = "保存成功！";
            else if (bar.AnswerType == BaseAnswer.Answers.Failure)
                bar.AnswerMeg = "保存失败，请重试！";
            return bar;
        }

         /// <summary>
        /// 根据房屋ID获取信息集合
        /// </summary>
        /// <returns></returns>
        public static List<CredentialInfo> GetCredentialInfoList(CredentialInfo ci)
        {
            return CredentialInfo_DAL.GetCredentialInfoList(ci);
        }

        /// <summary>
        /// 修改房屋证件信息
        /// </summary>
        /// <param name="ci"></param>
        /// <returns></returns>
        public static BaseAnswer UpdateCredentialInfo(CredentialInfo ci)
        {
            BaseAnswer bar = CredentialInfo_DAL.UpdateCredentialInfo(ci);
            if (bar.AnswerType == BaseAnswer.Answers.Succee)
                bar.AnswerMeg = "修改成功！";
            else if (bar.AnswerType == BaseAnswer.Answers.Failure)
                bar.AnswerMeg = "修改失败，请重试！";
            return bar;
        }


        /// <summary>
        /// 审批
        /// </summary>
        /// <param name="pi"></param>
        /// <returns></returns>
        public static BaseAnswer ApplyPushMeg(CredentialInfo ci)
        {
            BaseAnswer bar = CredentialInfo_DAL.ApplyPushMeg(ci);
            if (bar.AnswerType == BaseAnswer.Answers.Succee)
                bar.AnswerMeg = "审批成功！";
            else if (bar.AnswerType == BaseAnswer.Answers.Failure)
                bar.AnswerMeg = "审批失败，请重试！";
            return bar;
        }

        /// <summary>
        /// 获取推送消息集合，根据用户权限
        /// </summary>
        /// <returns></returns>
        public static List<CredentialInfo> GetPushMegList(PropertyInfo pi)
        {
            return CredentialInfo_DAL.GetPushMegList(pi);
        }
    }
}
